package com.mallcloud.mall.app.api.entity.dto;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.mallcloud.mall.common.core.constant.enums.app.WxPayEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;

@ApiModel(value="WxPay3UnifiedOrderInfoDTO",description="微信统一下单请求参数")
@Data
public class WxPay3UnifiedOrderInfoDTO implements Serializable {
	private static final long serialVersionUID = 1L;

	@ApiModelProperty(value="标价金额(单位为分)")
	@JSONField(serialize = false)
	private String totalFee;

	@ApiModelProperty(value="付款人openId")
	@JSONField(serialize = false)
	private String openId;

    @ApiModelProperty("小程序唯一标识(在微信小程序管理后台获取)")
	@JSONField(name = "appid")
    private String appId;

    @ApiModelProperty("商品描述")
    private String description;

    @ApiModelProperty("商户号")
	@JSONField(name = "mchid")
    private String mchId;

    @ApiModelProperty("通知地址")
	@JSONField(name = "notify_url")
    private String notifyUrl;

    @NotBlank(message = "商户订单号不能为空")
    @ApiModelProperty("商户订单号")
	@JsonProperty("out_trade_no")
	@JSONField(name = "out_trade_no")
    private String outTradeNo;

    @ApiModelProperty("金额")
    private Amount amount;

    @ApiModelProperty("场景")
	@JSONField(name = "scene_info")
    private SceneInfo sceneInfo;

    @ApiModelProperty("付款人")
    private Payer payer;

	/**
	 * {@link WxPayEnum.TradeTypeEnum}
	 */
	@ApiModelProperty("交易类型")
	@JsonProperty("trade_type")
	@JSONField(name = "trade_type")
	private String tradeType;
	public void setTradeType(String tradeType) {
		if(StrUtil.isNotBlank(tradeType)){
			this.tradeType = WxPayEnum.TradeTypeEnum.JSAPI.name();
		}else{
			this.tradeType = tradeType;
		}
	}

	@ApiModel(value="Amount",description="金额明细")
    @Data
    public static class Amount{
		@ApiModelProperty("总金额")
    	private Long total;
		@ApiModelProperty("币种")
    	private String currency = "CNY";
	}

	@ApiModel(value="SceneInfo",description="场景明细")
    @Data
    public static class SceneInfo{

		@ApiModelProperty("客户端IP")
		@JSONField(name = "payer_client_ip")
    	private String payerClientIp;

    	@ApiModelProperty("商户端设备号（门店号或收银设备ID）")
		@JSONField(name = "device_id")
    	private String deviceId = "127.0.0.1";
	}

	@ApiModel(value="Payer",description="付款人明细")
    @Data
    public static class Payer{

		@ApiModelProperty("付款人openId")
		@JSONField(name = "openid")
    	private String openId;
	}
}